package com.definity.toolkit.web.taglib;

import javax.servlet.jsp.JspException;

import com.definity.toolkit.i18n.I18n;
import com.definity.toolkit.i18n.I18nFactory;

public class RadioBooleanTag extends ComponentFormTag {

	private static final long serialVersionUID = -2340727515658471203L;

	@Override
	protected String getComponentName() {
		return "radio-boolean";
	}

	@Override
	protected String createStartTag(String name, String id, Object value) throws JspException {
		String styleClass = createStyleClass("boolean");
		
		I18n i18n = I18nFactory.getApplication();
		
		Boolean val = (Boolean) value;
		
		StringBuilder html = new StringBuilder();
		html.append("<input id=\"resolvido\" type=\"radio\" " + styleClass + " name=\"" + id + "\" id=\"" + id + "\" value=\"true\" " + (val != null && val ? "checked" : "") + " />");
		html.append("<span " + styleClass + ">");
		html.append(i18n.tl("Boolean.true"));
		html.append("</span>");
		html.append("<input id=\"naoResolvido\" type=\"radio\" " + styleClass + " name=\"" + id + "\" id=\"" + id + "\" value=\"false\" " + (val != null && !val ? "checked" : "") + " />");
		html.append("<span " + styleClass + ">");
		html.append(i18n.tl("Boolean.false"));
		html.append("</span>");
		return html.toString();
	}

	@Override
	protected String createEndTag(String name, String id, Object value) throws JspException {
		return "";
	}

}
